package com.YCH.user.controller.v1;

import com.YCH.apis.user.apis.UserLVControllerApi;
import com.YCH.model.common.dtos.ResponseResult;
import com.YCH.model.common.enums.AppHttpCodeEnum;
import com.YCH.user.service.AppUserLvService;
import com.YCH.utils.common.IdsUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/user_lv")
@Log4j2
public class UserLVController implements UserLVControllerApi {
    @Autowired
    private AppUserLvService appUserLvService;

    @Override
    @GetMapping("/load/task/{userId}")
    public ResponseResult loadUserLVTask(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.ObtainUserTaskInfo(id);
    }

    @Override
    @GetMapping("/load/lv/{userId}")
    public ResponseResult loadUserLVAndExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.ObtainUserLVAndExperience(id);
    }

    @Override
    @GetMapping("/sing_in/{userId}")
    public ResponseResult singIn(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.UserSignIn(id);
    }

    @Override
    @GetMapping("/publish/{userId}")
    public ResponseResult publishArticleExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getPublishArticleExperience(id);
    }

    @Override
    @GetMapping("/comment/{userId}")
    public ResponseResult publishCommentExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getCommentExperience(id);
    }

    @Override
    @GetMapping("/fabulous/{userId}")
    public ResponseResult fabulousExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getFabulousExperience(id);
    }

    @Override
    @GetMapping("/fabuloused/{userId}")
    public ResponseResult fabulousedExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getFabulousedExperience(id);
    }

    @Override
    @GetMapping("/replay/{userId}")
    public ResponseResult publishReplayExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getReplayExperience(id);
    }

    @Override
    @GetMapping("/replayed/{userId}")
    public ResponseResult replayedExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getReplayedExperience(id);
    }

    @Override
    @GetMapping("/like/{userId}")
    public ResponseResult likeExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getFollowExperience(id);
    }

    @Override
    @GetMapping("/followed/{userId}")
    public ResponseResult followExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getFollowedExperience(id);
    }

    @Override
    @GetMapping("/collection/{userId}")
    public ResponseResult collectionExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getCollectionExperience(id);
    }

    @Override
    @GetMapping("/collectioned/{userId}")
    public ResponseResult collectionedExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getCollectionedExperience(id);
    }

    @Override
    @GetMapping("/exquisit/{userId}")
    public ResponseResult exquisitExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getEXQUISITExperience(id);
    }

    @Override
    @GetMapping("/exquisited/{userId}")
    public ResponseResult exquisitedExperience(@PathVariable String userId) {
        long id = 0;
        try {
            id = IdsUtils.decryptLong(userId);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        return appUserLvService.getExquisitedExperience(id);
    }
}
